package pinboard.dataLayer.binPack;

import java.io.IOException;

import pinboard.dataLayer.RefBag;

public class BinSerializer {
    static BinSerializeMgr smgr;
    static BinDeserializeMgr dmgr;

    static {
        PackAttributeCache cache = new PackAttributeCache();
        smgr = new BinSerializeMgr(cache);
        dmgr = new BinDeserializeMgr(cache);
    }

    public static <T> byte[] toBytes(T input, Class<T> tClass) throws IOException {
        return smgr.toBytes(input, tClass);
    }

    public static <T> T toObject(byte[] input, Class<T> tClass) throws IOException {
        RefBag<Integer> offset = new RefBag<>();
        offset.data = 0;
        return toObject(input, offset, tClass);
    }

    public static <T> T toObject(byte[] input, RefBag<Integer> offset, Class<T> tClass) throws IOException {
        return dmgr.toObject(input, offset, tClass);
    }
}